package com.haixiaoke.saas.enterprise.house.controller;

import java.util.List;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.house.domain.HouseLabel;
import com.haixiaoke.saas.house.service.IHouseLabelService;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.system.framework.security.util.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 房屋标签Controller
 * 
 * @author panda
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/enterprise/house/label")
public class EnterpriseHouseLabelController extends BaseController {
    @Autowired
    private IHouseLabelService houseLabelService;

    /**
     * 查询房屋标签列表
     */
    @GetMapping("/list")
    public AjaxResult list(HouseLabel houseLabel) {
        houseLabel.setTenantId(getLoginUser().getTenantId());
        List<HouseLabel> list = houseLabelService.selectHouseLabelList(houseLabel);
        return success(list);
    }

    /**
     * 获取房屋标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId) {
        return success(houseLabelService.selectHouseLabelByLabelId(labelId));
    }

    /**
     * 新增房屋标签
     */
    @Log(title = "房屋标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseLabel houseLabel) {
        houseLabel.setTenantId(getLoginUser().getTenantId());
        int result = houseLabelService.checkHouseLabel(houseLabel);
        if (result > 1) {
            return error("标签名称重复，请重新输入！");
        }
        return toAjax(houseLabelService.insertHouseLabel(houseLabel));
    }

    /**
     * 修改房屋标签
     */
    @Log(title = "房屋标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseLabel houseLabel) {
        return toAjax(houseLabelService.updateHouseLabel(houseLabel));
    }

    /**
     * 删除房屋标签
     */
    @Log(title = "房屋标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds) {
        return toAjax(houseLabelService.deleteHouseLabelByLabelIds(labelIds));
    }
}
